package cn.gson.springboot.controller;

import cn.gson.springboot.model.pojos.Demand;
import cn.gson.springboot.model.pojos.Employee;
import cn.gson.springboot.model.service.DemandService;
import cn.gson.springboot.model.vo.QuotationVo;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class DemandController {
    @Autowired
    DemandService demandService;
    @Autowired
    HttpSession session;

    // 查询员工需求集合
    @RequestMapping("/demand-list")
    @ResponseBody
    public Map<String,Object> allDemandList(Integer page,Integer size,Integer filter,Integer vague,String content){
        Page<Object> objects = PageHelper.startPage(page, size);
        Employee emp =(Employee) session.getAttribute("emp");
        List<Demand> demands = demandService.selectEmpDemand(emp.getDepartment().getDeptId(),filter,vague,content);
        Map<String,Object> map = new HashMap<>();
        map.put("rows",demands);
        map.put("total",objects.getTotal());
        return map;
    }

    // 按机会Id查询员工需求集合
    @RequestMapping("/demand-opp-list")
    @ResponseBody
    public List<Demand> allDemandOppIdList(Integer oppId){
        List<Demand> demands = demandService.selectDemandByOppId(oppId);
        return demands;
    }

    @RequestMapping("/save-demand")
    @ResponseBody
    public void saveDemand(@RequestBody Demand demand){
        demandService.saveDemand(demand);
    }

    @RequestMapping("/delete-demand")
    @ResponseBody
    public void deleteDemand(@RequestParam(value = "demandId") Integer demandId){
        demandService.deleteDemand(demandId);
    }
}
